package shuaige.jdk.多线程.锁.可重入锁_synchronized;

public class 线程同步_未加锁 {
    public static void main(String[] args) throws Exception {
        var add = new AddThread_未加锁();
        var dec = new DecThread_未加锁();
        add.start();
        dec.start();
        add.join();
        dec.join();
        System.out.println(Counter_未加锁.count);
    }
}

class Counter_未加锁 {
    // 被加的数字
    public static int count = 0;
}

class AddThread_未加锁 extends Thread {
    @Override
    public void run() {
        // 加10000次
        for (int i = 0; i < 10000; i++) {
            Counter_未加锁.count += 1;
        }
    }
}

class DecThread_未加锁 extends Thread {
    @Override
    public void run() {
        // 减10000次
        for (int i = 0; i < 10000; i++) {
            Counter_未加锁.count -= 1;
        }
    }
}